//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    _height:wx.getMenuButtonBoundingClientRect().height,
    _top_hieght: wx.getMenuButtonBoundingClientRect().height+wx.getMenuButtonBoundingClientRect().top+10,
    p_top:wx.getMenuButtonBoundingClientRect().top,
    _qd:false
  },
  //事件处理函数
  onLoad: function () {
    wx.ajax('/home/banner/',{id:1}).then((e=>{
      this.setData({
        banner:e.lists
      })
    }))
  },

  // 扫码领取红包？
  saoma:function(){
    var _this=this;
    var _usr_identity="";
    wx.ajax('/user/index', {}, 'get', true).then(res=>{
      _usr_identity=res.user.identity;
      wx.scanCode({
        onlyFromCamera: true,
        success (res) {
          var _usr=res.result.split('n=')[1]
          // _usr=_usr+Math.floor(Math.random()*100+1)
          if(_usr.substr(0,8)=='11515151' && _usr.substr(11,5)=='61044' ){
          
            if(_usr_identity==2){
              if(_usr.substr(16,1)=='1'){
                  // 农民? 种植者
                  wx.ajax('/scan/code',{code:_usr}).then(es=>{
                    wx.navigateTo({
                      url: '/pages/game/index?code='+_usr,
                    })
                  })
              }else
              { 
                wx.showToast({
                  title: '身份不匹配, 经销商可以扫',
                  icon:'none'
                }) 
              }
            }
            if(_usr_identity==1){
              if(_usr.substr(16,1)=='2' || _usr.substr(16,1)=='3'){
                // 、、 经销商
                wx.ajax('/scan/code',{code:_usr}).then(es=>{
                  wx.navigateTo({
                    url: '/pages/game/index?code='+_usr,
                  })
                })
  
              }else
              {
                wx.showToast({
                  title: '身份不匹配,种植可扫',
                  icon:'none'
                }) 
              }
            }
            
          }else
          {
            wx.showToast({
              title: '二维码无效',
              icon:'none'
            })
          }
        
         
        }
       
      })
    })

  },
  // 会议签到 扫码
  code:function(){

    if(!wx.getStorageSync('uid')){
        wx.navigateTo({
          url: '/pages/userauthorization/index',
        })
        return false
    }
 
    var _this=this;
    wx.scanCode({
      onlyFromCamera: true,
      success (res) {
        
        if(res.path)
        { 
          wx.ajax('/meet/details/'+res.path.split('=')[1]).then(r=>{
            _this.setData({
               cod_qd:r
            })
            _this.setData({
              _qd_code:true
            })
          }).catch(err=>{
            wx.showToast({
              title: '无效会议签到二维码',
              icon:'none'
            })
          })
         
        }else
        {
          wx.showToast({
            title: '二维码无效',
            icon:'none'
          })
        }
       
      }
     
    })


  },
  // 会议确签到
  hui_qd:function(e){
   
   var _this=this;
    wx.ajax('/meet/sing/'+e.currentTarget.dataset.id).then(res=>{
      wx.showToast({
        title:res.message,
        icon:'none'
      })
      _this.setData({
        _qd_code:false
      }) 
    },err=>{
      _this.setData({
        _qd_code:false
      }) 
    })
  },
  // 用户日常签到
  user_qd:function(){
    wx.ajax('/day/sing',{},'get',true).then(res=>{
      this.setData({
        _qd:true, 
        qd_data:res.data
      })
    })
   
  },

  yes:function(){
    this.cllear()
  },
  cllear:function(){
    this.setData({
      _qd:false,
      _qd_code:false
    })
  },
    /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
